home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / update.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  8.1 KB  |  250 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import spamexperts
  5. import spamexperts.se_logging as spamexperts
  6. spamexperts.se_logging.setup('SpamExpertsUpdate')
  7. import os
  8. import sys
  9. import time
  10. import gettext
  11. import spamexperts.resources as spamexperts
  12. import spamexperts.software_update as spamexperts
  13.  
  14. try:
  15.     _
  16. except NameError:
  17.     _ = gettext.gettext
  18.     import __builtin__
  19.     __builtin__.__dict__['_'] = _
  20.  
  21.  
  22. def simple_dialog(msg, can_cancel = False, yes_no = False):
  23.     import wx
  24.     if can_cancel:
  25.         flags = wx.OK | wx.ICON_INFORMATION | wx.CANCEL
  26.     elif yes_no:
  27.         flags = wx.YES_NO | wx.ICON_QUESTION
  28.     else:
  29.         flags = wx.OK | wx.ICON_INFORMATION
  30.     d = wx.MessageDialog(None, msg, 'SpamExperts', flags)
  31.     result = d.ShowModal()
  32.     if yes_no:
  33.         if result == wx.ID_YES:
  34.             result = wx.ID_OK
  35.         elif result == wx.ID_NO:
  36.             result = wx.ID_CANCEL
  37.         
  38.     
  39.     d.Destroy()
  40.     return result
  41.  
  42.  
  43. def complete_update():
  44.     import wx
  45.     initial_version = spamexperts.__version__
  46.     progress_style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME
  47.     if 'continue' in sys.argv:
  48.         initial = _('Resuming update.')
  49.     else:
  50.         initial = _('Starting update.')
  51.     dlg = wx.ProgressDialog(_('SpamExperts Update'), initial, maximum = 100, style = progress_style)
  52.     software_update = spamexperts.software_update
  53.     exe_dir = spamexperts.resources.application_directory()
  54.     updater = software_update.CompleteUpdate()
  55.     updater.update()
  56.     dlg.Destroy()
  57.     if initial_version.startswith('1.0.'):
  58.         convert()
  59.     
  60.  
  61.  
  62. def convert(files = True, logs = True, lsp = True, copyfile = True, shortcuts = True):
  63.     LSP_INI_FULLPATH = LSP_INI_FULLPATH
  64.     import se_config
  65.     options = options
  66.     import spamexperts.Options
  67.     shell = shell
  68.     shellcon = shellcon
  69.     import win32com.shell
  70.     data_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
  71.     if files:
  72.         for cache, opt in (('spam', 'spam_cache'), ('ham', 'ham_cache'), ('unsure', 'unsure_cache'), ('unknown', 'unknown_cache'), ('to_be_removed', 'to_be_removed_cache')):
  73.             cache = os.path.join(data_dir, options[('Storage', 'user_data_dir')], cache)
  74.             if os.path.isdir(cache):
  75.                 files = os.listdir(cache)
  76.                 for f in files:
  77.                     full_f = os.path.join(cache, f)
  78.                     out_f = os.path.join(data_dir, options[('Storage', 'user_data_dir')], options[('Storage', opt)], f)
  79.                     encrypt(full_f, out_f)
  80.                     os.remove(full_f)
  81.                 
  82.                 os.rmdir(cache)
  83.                 continue
  84.         
  85.     
  86.     if logs:
  87.         for i in xrange(4):
  88.             
  89.             try:
  90.                 os.remove(os.path.join(spamexperts.se_logging.log_dir, 'SpamExpertsServer%d.log' % (i,)))
  91.             continue
  92.             except OSError:
  93.                 continue
  94.             
  95.  
  96.         
  97.     
  98.     if lsp:
  99.         convert_lsp(LSP_INI_FULLPATH)
  100.     
  101.     if copyfile:
  102.         convert_copyfile()
  103.     
  104.     if shortcuts:
  105.         STARTMENU = shellcon.CSIDL_STARTMENU
  106.         COMMON = shellcon.CSIDL_COMMON_STARTMENU
  107.         
  108.         try:
  109.             start = shell.SHGetFolderPath(0, STARTMENU, 0, 0)
  110.         except pywintypes.com_error:
  111.             start = None
  112.  
  113.         
  114.         try:
  115.             common = shell.SHGetFolderPath(0, COMMON, 0, 0)
  116.         except pywintypes.com_error:
  117.             common = None
  118.  
  119.         for version in ('Programs', 'All Programs'):
  120.             for user in (start, common):
  121.                 if user:
  122.                     continue
  123.                 _[1][user]
  124.             
  125.         
  126.     
  127.  
  128.  
  129. def convert_copyfile():
  130.     import _winreg
  131.     import tempfile
  132.     key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce')
  133.     i = 0
  134.     replacements = []
  135.     while True:
  136.         
  137.         try:
  138.             (name, unused, command) = _winreg.EnumValue(key, i)
  139.         except WindowsError:
  140.             break
  141.  
  142.         i += 1
  143.         if name == 'update-se':
  144.             _winreg.DeleteValue(key, name)
  145.             continue
  146.         
  147.         
  148.         try:
  149.             (unused, new, old) = command.split('" "')
  150.         except ValueError:
  151.             continue
  152.  
  153.         old.rstrip('"')
  154.         _winreg.DeleteValue(key, name)
  155.         replacements.append((old, new))
  156.     if not replacements:
  157.         return None
  158.     
  159.     fn = os.path.join(tempfile.tempdir, 'spamexperts_update', 'in_use.txt')
  160.     f = file(fn, 'w')
  161.     f.write('"%s" continue relaunch\n' % (sys.executable,))
  162.     for old, new in replacements:
  163.         f.write('%s\n%s\n' % (new, old))
  164.     
  165.     f.close()
  166.     cmd = os.path.join(os.path.dirname(sys.executable), 'copyfile.exe ' + fn)
  167.     key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce')
  168.     _winreg.SetValueEx(key, 'spamexperts update', 0, _winreg.REG_SZ, cmd)
  169.  
  170.  
  171. def add(ports):
  172.     ports.extend([
  173.         '995',
  174.         '993'])
  175.     return ports
  176.  
  177.  
  178. def convert_lsp(LSP_INI_FULLPATH):
  179.     options = options
  180.     import spamexperts.Options
  181.     dest_port = options[('globals', 'proxy_redirection_port')]
  182.     apps = { }
  183.     ports = { }
  184.     for line in file(LSP_INI_FULLPATH):
  185.         (exe, port, to, description) = line.split(',')
  186.         apps[exe] = description
  187.         
  188.         try:
  189.             ports[exe].append(port)
  190.         continue
  191.         except KeyError:
  192.             ports[exe] = [
  193.                 port]
  194.             continue
  195.         
  196.  
  197.     
  198.     ports = dict((lambda [outmost-iterable]: for exe, port in [outmost-iterable]:
  199. (exe, add(port)))(ports.iteritems()))
  200.     revised = file(LSP_INI_FULLPATH, 'w')
  201.     for exe, port_list in ports.iteritems():
  202.         for port in port_list:
  203.             revised.write('%s,%s,%s,%s\n' % (exe, port, dest_port, apps[exe].rstrip()))
  204.         
  205.     
  206.     revised.close()
  207.  
  208.  
  209. def encrypt(pn, out_pn):
  210.     options = options
  211.     import spamexperts.Options
  212.     AES = AES
  213.     import Crypto.Cipher
  214.     if options[('globals', 'verbose')]:
  215.         print 'Converting', pn, '...',
  216.     
  217.     key = '%.16i' % hash(out_pn.lower())[:16]
  218.     crypt = AES.new(key)
  219.     msg = file(pn).read()
  220.     msg = crypt.encrypt(msg + '\x00' * (16 - len(msg) % 16))
  221.     
  222.     try:
  223.         os.makedirs(os.path.dirname(out_pn))
  224.     except OSError:
  225.         pass
  226.  
  227.     file(out_pn, 'wb').write(msg)
  228.     if options[('globals', 'verbose')]:
  229.         print '... converted'
  230.     
  231.  
  232. if __name__ == '__main__':
  233.     if 'convert_data' in sys.argv:
  234.         print 'Converting data at', time.asctime(time.localtime())
  235.         convert()
  236.     else:
  237.         import sys
  238.         import urllib
  239.         import _winreg
  240.         (v_file, unused) = urllib.urlretrieve('http://update2.spamexperts.com/version.txt')
  241.         content = file(v_file).read()
  242.         if '<html>' in content.lower() and '404' in content:
  243.             sys.exit()
  244.         
  245.         version = content.strip()
  246.         urllib.urlcleanup()
  247.         key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\SpamExperts')
  248.         _winreg.SetValueEx(key, 'LatestBuild', 0, _winreg.REG_SZ, version)
  249.  
  250.